//
//  JMStagemenDetailVController.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/5/10.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMStagemenDetailVController.h"
#import "JMStagemenDetailReturn.h"
@interface JMStagemenDetailVController ()
@property(nonatomic,weak)UIImageView *headImage;
@property(nonatomic,weak)UIImageView *personImage;
@property(nonatomic,weak)UILabel *nameLabel;
@property(nonatomic,weak)UILabel *bindingLab;
@property(nonatomic,weak)UILabel *bindingNumL;

@property(nonatomic,weak)UILabel *levelLab;
@property(nonatomic,weak)UILabel *levelNumL;
@property(nonatomic,weak)UILabel *winProbability;
@property(nonatomic,weak)UILabel *winProbaNum;
@end

@implementation JMStagemenDetailVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createViews];
    [self createButton];
    UserEntity *user = [UserEntity shardUserInfo];


    NSString *token = user.access_token;
    
    [self requestGetStrategyPeopleInfoWithToken:token StrategyPeopleId:self.stagemenInfo.Id];
   
}
-(void)createViews
{
    CGFloat labelY = 320/3;
    CGFloat labelW=100;
    CGFloat labelH = 30;
    UIImageView *headImage = [ARC createImageViewWithFrame:CGRectMake(0, 0, 320, 180) ImageName:@""];
    self.headImage = headImage;
    headImage.backgroundColor = [UIColor grayColor];
    [self.view addSubview:headImage];
    
    
    UIImageView *personImage = [ARC createImageViewWithFrame:CGRectMake(20, 60, labelH, labelH) ImageName:@""];
    self.personImage = personImage;
    [self.view addSubview:personImage];

    UILabel *titleLab = [ARC createLabelWithFrame:CGRectMake(0,20, 320, labelH) Font:14 Text:nil];
    titleLab.text = @"策略员";
    titleLab.textColor = [UIColor whiteColor];
    [self.view addSubview:titleLab];
    
    UILabel *nameLab = [ARC createLabelWithFrame:CGRectMake(labelH+10,60, labelW, labelH) Font:13 Text:nil];
    self.nameLabel = nameLab;
    [self.view addSubview:nameLab];
    
    UILabel *levelLab = [ARC createLabelWithFrame:CGRectMake(10,140, labelY, labelH) Font:13 Text:nil];
    self.levelLab = levelLab;
    self.levelLab.text = @"级别";
    [self.view addSubview:levelLab];
    UILabel *levelNumL = [ARC createLabelWithFrame:CGRectMake(10, 110, labelY, labelH) Font:13 Text:nil];
    self.levelNumL = levelNumL;
    [self.view addSubview:levelNumL];
    
    UILabel *winprobilyty = [ARC createLabelWithFrame:CGRectMake(labelY,140, labelY, labelH) Font:13 Text:@"胜率"];
    self.winProbability = winprobilyty;
    [self.view addSubview:winprobilyty];
    
    UILabel *winProbilNum = [ARC createLabelWithFrame:CGRectMake(labelY, 110, labelY, labelH) Font:13 Text:nil];
    self.winProbaNum = winProbilNum;
    [self.view addSubview:winProbilNum];
    
    
    UILabel *bindingL = [ARC createLabelWithFrame:CGRectMake(labelY*2,140, labelY, labelH) Font:13 Text:nil];
    self.bindingLab = bindingL;
    bindingL.text = @"绑定";
     [self.view addSubview:bindingL];
    
    UILabel *bindingNumL = [ARC createLabelWithFrame:CGRectMake(labelY*2, 110, labelY, labelH) Font:13 Text:nil];
    self.bindingNumL = bindingNumL;
    [self.view addSubview:bindingNumL];

    self.headImage.frame = [ToolViewAndData MyAutoLayout:headImage];
    self.personImage.frame = [ToolViewAndData MyAutoLayout:self.personImage];
    self.nameLabel.frame = [ToolViewAndData MyAutoLayout:self.nameLabel];
    self.bindingLab.frame =[ToolViewAndData MyAutoLayout:self.bindingLab];
    self.levelLab.frame = [ToolViewAndData MyAutoLayout:self.levelLab];
    self.levelNumL.frame = [ToolViewAndData MyAutoLayout:self.levelNumL];
    
    self.winProbability.frame = [ToolViewAndData MyAutoLayout:self.winProbability];
    self.winProbaNum.frame = [ToolViewAndData MyAutoLayout:self.winProbaNum];
    
    self.nameLabel.textColor = [UIColor whiteColor];
    self.bindingLab.textColor = [UIColor whiteColor];
    self.bindingNumL.textColor = [UIColor whiteColor];
    self.levelNumL.textColor = [UIColor whiteColor];
    self.levelLab.textColor = [UIColor whiteColor];
     self.winProbability.textColor = [UIColor whiteColor];
    self.winProbaNum.textColor = [UIColor whiteColor];

}
-(void)requestGetStrategyPeopleInfoWithToken:(NSString*)token StrategyPeopleId:(NSString*)strategyPeopleId
{
    NSString *url = [NSString stringWithFormat:@"%@%@&StrategyPeopleId=%@",JMURLGetStrategyPeopleInfo,token,strategyPeopleId];
    NSArray *arrayR = @[@"",url,@"GET"];
    [Request startRequestWithArray:arrayR FinishedBlock:^(NSData *data) {
        NSDictionary *dict = [JMData dictAndTestData:data];
        JMStagemenDetailReturn *stagemenDetail = [JMStagemenDetailReturn objectWithKeyValues:dict];
        
        if ([stagemenDetail.State intValue]>= 0)
        {
            JMStagemenDetailInfo *stagemenDetailInfo = [JMStagemenDetailInfo objectWithKeyValues:stagemenDetail.data];
            [JMData requestOrSetImgWithImageView:self.personImage ProductImageUrl:stagemenDetailInfo.HeadImg];

            self.nameLabel.text = stagemenDetailInfo.NickName;
            self.levelNumL.text = stagemenDetailInfo.Level;
            self.winProbaNum.text =[NSString stringWithFormat:@"%@%%",stagemenDetailInfo.PutWinRate];
            self.bindingNumL.text = stagemenDetailInfo.IsBind;
        }

        
            
    } FailBlock:^(NSString *string) {
        SHOWALERT(@"服务器繁忙，请梢后重试");
    }];
}


- (void)createButton{
    
    CGFloat btnX = 200;
    CGFloat btnH = 40;

    UIButton* applyBindingBtn = [ARC createButtonWithFrame:CGRectMake(10,btnX, 140, btnH-5)
                                             Target:self
                                                       Sel:@selector(applyBindingBtnClick:)
                                              Title:@"申请绑定"];
    [applyBindingBtn setBackgroundImage:[UIImage imageNamed:@"logoin_btn"] forState:UIControlStateNormal];
    applyBindingBtn.frame = [ToolViewAndData MyAutoLayout:applyBindingBtn];
    [applyBindingBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
    applyBindingBtn.tintColor=[UIColor whiteColor];
    [self.view addSubview:applyBindingBtn];
    
    UIButton* cancelBindingBtn = [ARC createButtonWithFrame:CGRectMake(170,btnX, 140, btnH-5)
                                              Target:self
                                                        Sel:@selector(cancelBindingBtnClick:)
                                               Title:@"取消绑定"];
    [cancelBindingBtn setBackgroundImage:[UIImage imageNamed:@"aut_ico_register"] forState:UIControlStateNormal];
    [cancelBindingBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:16]];
    cancelBindingBtn.frame = [ToolViewAndData MyAutoLayout:cancelBindingBtn];
    cancelBindingBtn.tintColor=[UIColor redColor];
    
    [self.view addSubview:cancelBindingBtn];
    
    
}


-(void)applyBindingBtnClick:(UIButton*)btn
{

    
}

- (void)cancelBindingBtnClick:(UIButton*)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
